import { defineStore } from 'pinia'

export const roleStore = defineStore('role', {
  state: () => {
    return {
      businessLevel: 0, // 业绩等级  0: 普通用户 1: 普通 2: 初级 3: 高级
      supplyLevel: 0, // 供应链等级  0: 普通用户 1: 普通 2: 初级 3: 高级
      financeLevel: 0, // 财务等级  0: 普通用户 1: 普通 2: 初级 3: 高级
      humanLevel: 0, // 财务等级  0: 普通用户 1: 普通 2: 初级 3: 高级
      testRole: false, // 测试角色是否展示
    }
  },

  actions: {
    // 设置角色
    setRole(role1: number, role2: number, role3: number, role4: number) {
      this.businessLevel = role1
      this.supplyLevel = role2
      this.financeLevel = role3
      this.humanLevel = role4
    },
    setBusinessLevel(businessLevel) {
      this.businessLevel = businessLevel
    },
    setSupplyLevel(supplyLevel) {
      this.supplyLevel = supplyLevel
    },
    setFinanceLevel(financeLevel) {
      this.financeLevel = financeLevel
    },
    setHumanLevel(humanLevel) {
      this.humanLevel = humanLevel
    },
    setTestRole() {
      this.testRole = !this.testRole
    },
    // 清空
    clear() {
      this.businessLevel = 0
      this.supplyLevel = 0
      this.financeLevel = 0
      this.humanLevel = 0
      this.testRole = false
    },
  },
  persist: {
    enabled: true,
  },
})
// 如果是开发环境，可以在控制台直接访问roleStore，方便调试。
if (process.env.NODE_ENV === 'development') {
  window['_ROlE_STORE'] = roleStore
}
